﻿using IcsSEMCtrl.Com.Secs;
using IcsSEMCtrl.Service.Logger;
using Lifter.Device;
using SEComEnabler.SEComStructure;
using System;
using TKT.Lifter.CIM.Lifter.HSMSMsg.HSMSConstant;

namespace TKT.Lifter.CIM.Lifter.HSMSMsg.TransferActionMsg
{
    public class S2F42
    {
        public static void MakeTransactionSend(string sxfx, SecsEventArgs secsEvent, LifterSEM lifterSEM)
        {
            SecsValue secsValue = secsEvent.SecsValue;
            SXTransaction sXTransaction = new SXTransaction();
            sXTransaction.Stream = 2;
            sXTransaction.Function = 42;
            sXTransaction.Wait = false;
            try
            {
                string sRCMD = ((SEComData)secsValue.SecsData).DataItems[0][0].Value.ToString();
                if (sRCMD != null)
                {
                    if (sRCMD == "RESUME")
                    {
                        bool flag = lifterSEM.ReplyS2F41Resume(ref sXTransaction);
                        lifterSEM.SecsDriver.ReplyMessage(sxfx, sXTransaction, secsValue);
                        if (flag)
                        {
                            lifterSEM.DoResume();
                        }
                    }
                    else if (sRCMD == "PAUSE")
                    {
                        bool flag = lifterSEM.ReplyS2F41Pause(ref sXTransaction);
                        lifterSEM.SecsDriver.ReplyMessage(sxfx, sXTransaction, secsValue);
                        if (flag)
                        {
                            lifterSEM.DoPause();
                        }
                    }
                    else if (sRCMD == "PORTTYPECHANGE")
                    {
                        lifterSEM.ReplyS2F41PORT_TYPE_CHANGE(ref sXTransaction, (SEComData)secsValue.SecsData);
                        lifterSEM.SecsDriver.ReplyMessage(sxfx, sXTransaction, secsValue);
                    }
                    else if (sRCMD == "ENTRYVALIDATION")
                    {
                        lifterSEM.ReplyS2F41EntryValidation(sxfx, sXTransaction, secsValue);
                    }
                    else if (sRCMD == "INSTALL")
                    {
                        lifterSEM.ReplyS2F41Install(sxfx, sXTransaction, secsValue);
                    }
                    else
                    {
                        LogHelper.loggerInfo($"S2F42指令[{sRCMD}]不存在");
                        sXTransaction.WriteNode(SX.SECSFormat.L, 2, "", "", new int[0]);
                        sXTransaction.WriteNode(SX.SECSFormat.B, 1, ((int)MsgACK.HCACK.COMMAND_DOES_NOT_EXIST).ToString(), "HACK", new int[0]);
                        sXTransaction.WriteNode(SX.SECSFormat.L, 0, "", "", new int[0]);
                        lifterSEM.SecsDriver.ReplyMessage(sxfx, sXTransaction, secsValue);
                    }
                    /*                    if (sRCMD == "SHUTTLEMOVE")
                                        {
                                            lifterSEM.ReplyS2F41SHUTTLEMOVE(sxfx, e);
                                        }*/
                }
            }
            catch (ArgumentOutOfRangeException ex)
            {
                Console.WriteLine("MakeTransactionSend(S2F42)");
                LogHelper.loggerError("在MakeTransactionSend(S2F42)中报错",ex);
            }
        }
    }
}
